package com.hnhcyy.goods.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.hnhcyy.goods.pojo.SpBal;

/**
 * 商品库存
 * @author sheyongjun  
 * @date 2019年2月16日
 */
public interface SpBalMapper {
	
	@Select("select spid,pihao,baozhiqi,sxrq,kxshl from sp_bal where spid=#{spid} limit 1")
	SpBal selectItemById(String spid);
	
	@Select("select count(*) from sp_bal where spid=#{spid}")
	int selectCountById(String spid);
	
	@Insert("insert into sp_bal (spid,pihao,baozhiqi,sxrq,kxshl) values \r\n" + 
			"(#{spid},ifnull(#{pihao},''),ifnull(#{baozhiqi},'1970-01-01'),ifnull(#{sxrq},'1970-01-01'),ifnull(#{kxshl},0))")
	int insertItem(SpBal spBal);
	
	@Update("update sp_bal set pihao=ifnull(#{pihao},''),baozhiqi=ifnull(#{baozhiqi},'1970-01-01'),sxrq=ifnull(#{sxrq},'1970-01-01'),kxshl=ifnull(#{kxshl},0)\r\n" + 
			"		where spid=#{spid} limit 1")
	int updateItem(SpBal spBal);
	
	int insertTmpByBatch(List<SpBal> spBalList);
	
	void truncateSpBalTmp();
	
	int replaceByBatch(List<SpBal> spBalList);
}
